<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  
</body>
<script>

  function Parent(){}

  function Child(){}

  Child.prototype = new Parent();
  
  const p = new Parent();

  const c = new Child();

  console.log( Parent.prototype.isPrototypeOf( p ) );
  console.log( p instanceof Parent );
  console.log("===");
  
  console.log( Child.prototype.isPrototypeOf( c ) );
  console.log( c instanceof Child );
  console.log("===");
  
  console.log( Parent.prototype.isPrototypeOf( c ) );
  console.log( c instanceof Parent );
  console.log("===");

  console.log( Child.prototype.isPrototypeOf( p ) );
  console.log( p instanceof Child );
  console.log("===");
  
  // 万物皆对象
  console.log( Object.prototype.isPrototypeOf( p ) );
  console.log( p instanceof Object );
  console.log( Object.prototype.isPrototypeOf( c ) );
  console.log( c instanceof Object );
  console.log( Object.prototype.isPrototypeOf( Parent ) );
  console.log( Parent instanceof Object );
  console.log( Object.prototype.isPrototypeOf( Child ) );
  console.log( Child instanceof Object );


  console.log("=======");


  // 如何区分对象，数组，伪数组，等其他typeof检测为object的数据类型
  // 利用原型指向判断数据类型
  
  const o = { length: 0 };
  const a = [];
  const li = document.querySelectorAll("li");
  const fArr = {
    0: "hello",
    1: 123,
    2: "hahah",
    length: 5
  }

  console.log(typeof o);
  console.log(typeof a);
  console.log(typeof li);
  console.log(li);
  console.log(fArr);

  for(let i=0;i<fArr.length;i++){
    console.log(fArr[i]);
  }
  
  console.log( o instanceof Array );
  console.log( a instanceof Array );
  console.log( li instanceof Array );
  console.log( fArr instanceof Array );


  // 万能数据类型检测
  console.log( Object.prototype.toString.call("hello") )
  console.log( Object.prototype.toString.call(123) )
  console.log( Object.prototype.toString.call({}) )
  console.log( Object.prototype.toString.call([]) )
  console.log( Object.prototype.toString.call(function(){}) )
  console.log( Object.prototype.toString.call(true))
  console.log( Object.prototype.toString.call(undefined))
  console.log( Object.prototype.toString.call(null))
  console.log( Object.prototype.toString.call(/a/))
  console.log( Object.prototype.toString.call(new Date()))
  console.log( Object.prototype.toString.call(new Set()))
  console.log( Object.prototype.toString.call(new Map()))




</script>
</html>